<template>
	<div>
		<!-- #ifdef MP-WEIXIN -->
		<button class="login-btn" open-type="getUserInfo" @getuserinfo="getuserinfo"><slot name="lBtn">登录/注册</slot></button>
		<!-- #endif -->
	</div>
</template>

<script>
export default {
	data() {
		return {};
	},
	created() {},
	methods: {
		getuserinfo(e) {
			this.$store.commit('commit_wxUserInfo', e.detail.userInfo);
			this.$emit('loginSuccess')
			uni.login({
				provider: 'weixin',
				success: res => {
					this.getOpenId(res.code);
				}
			});
		},
		getOpenId(code) {
			this.$u.api
				.getOpenId({
					code: code
				})
				.then(res => {
					this.$store.commit('commit_wxOpenId', res.data.openid);
					this.goPage('/pages/login/index');
				});
		}
	}
};
</script>

<style lang="scss">
.login-btn {
	font-size: 28rpx;
	// height: 40upx;
	// line-height: 40upx;
	background: transparent;
	color: $uni-color-primary;
	// width: 200upx;
	margin-left: 0;
	margin-right: 0;
}
.login-btn::after {
	border: 0 none;
}
</style>
